package com.supor.aiot.common.app.api;

import com.android.baseconfig.base.BaseApiResult;
import com.android.baseconfig.base.BaseRetrofit;
import com.android.baseconfig.base.DataApiResult;
import com.supor.aiot.common.entity.BannerInfo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.rxjava3.core.Observable;

/**
 * ---------------------------------------------------------------- <br>
 * Copyright (C) 2014-2021, by het, Shenzhen, All rights reserved.  <br>
 * ---------------------------------------------------------------- <br>
 * <p>
 * 描述: CommonImpl <br>
 * 作者: lei <br>
 * 日期: 2021/10/22 <br>
 */
public class CommonImpl extends BaseRetrofit<CommonService> implements CommonService {
    private static CommonImpl instance;

    public static CommonImpl getInstance() {
        if (instance == null) {
            instance = new CommonImpl();
        }
        return instance;
    }

    @Override
    public Observable<BaseApiResult<DataApiResult<List<BannerInfo>>>> getBanner(Map<String, Object> map) {
        return api.getBanner(map).compose(this.applySchedulers());
    }

    @Override
    public Observable<BaseApiResult<String>> getRecipe(int recipeId, String mac) {
        return api.getRecipe(recipeId, mac).compose(this.applySchedulers());
    }

    public Observable<BaseApiResult<DataApiResult<List<BannerInfo>>>> getBanner(int limit, String adType, String adStatus) {
        Map<String, Object> map = new HashMap<>();
        map.put("limit", limit);
        map.put("adType", adType);
        if (adStatus != null) {
            map.put("adStatus", adStatus);
        }
        return api.getBanner(map).compose(this.applySchedulers());
    }
}
